package lc.activiti.approseal.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import lc.activiti.approseal.service.IApprovalSealService;
import lc.activiti.common.HttpRequestStatus;
import lc.activiti.common.LCExceptionUtils;
import lc.activiti.common.Result;
import lc.activiti.model.SubApprovalModel;
import lombok.extern.slf4j.Slf4j;

@RequestMapping("/approvalSealService")
@Slf4j
@RestController
public class ApprovalSealController {
	
	@Autowired
	private IApprovalSealService approvalSealService;

	@RequestMapping("/deployApprovalSealProcess")
	public Result<Object> deployApprovalSealProcess(){
		Result<Object> result=new Result<>();
		try {
			approvalSealService.deployApprovalSealProcess();
			result.setMessage("【审批印章流程1.0】部署成功!");
			result.setStatus(HttpRequestStatus.Sucess.getStatus());
			return result;
		} catch (Exception e) {
			result.setMessage(LCExceptionUtils.getExpetionMessage(e));
			result.setStatus(HttpRequestStatus.Failed.getStatus());
			e.printStackTrace();
			log.error("【审批印章流程1.0】部署流程错误",e);
			return result;
		}
	}
	@RequestMapping("/submitApprovalSealApply")
	public Result<Object> submitApprovalSealApply(@RequestBody SubApprovalModel approvalModel){
		Result<Object> result=new Result<>();
		try {
			approvalSealService.submitApprovalSealApply(approvalModel);
			result.setMessage("提交成功!");
			result.setStatus(HttpRequestStatus.Sucess.getStatus());
			return result;
		} catch (Exception e) {
			result.setMessage(LCExceptionUtils.getExpetionMessage(e));
			result.setStatus(HttpRequestStatus.Failed.getStatus());
			e.printStackTrace();
			log.error("提交错误",e);
			return result;
		}
	}
	@RequestMapping("/approvalSealSuccess")
	public Result<Object> approvalSealSuccess(@RequestBody SubApprovalModel approvalModel){
		Result<Object> result=new Result<>();
		try {
			approvalSealService.approvalSealSuccess(approvalModel);
			result.setMessage("提交成功!");
			result.setStatus(HttpRequestStatus.Sucess.getStatus());
			return result;
		} catch (Exception e) {
			result.setMessage(LCExceptionUtils.getExpetionMessage(e));
			result.setStatus(HttpRequestStatus.Failed.getStatus());
			e.printStackTrace();
			log.error("提交错误",e);
			return result;
		}
	}
	@RequestMapping("/rejectApprovalSeal")
	public Result<Object> rejectApprovalSeal(@RequestBody SubApprovalModel approvalModel){
		Result<Object> result=new Result<>();
		try {
			approvalSealService.rejectApprovalSeal(approvalModel);
			result.setMessage("提交成功!");
			result.setStatus(HttpRequestStatus.Sucess.getStatus());
			return result;
		} catch (Exception e) {
			result.setMessage(LCExceptionUtils.getExpetionMessage(e));
			result.setStatus(HttpRequestStatus.Failed.getStatus());
			e.printStackTrace();
			log.error("提交错误",e);
			return result;
		}
	}
}
